<template>
    <div>
        <div class="bom_tree_search clearfix">
            <div class="tip">
                <label class="title">编码</label>
                <Input v-model.trim="code" placeholder="请输入编码" style="width: 200px" @on-enter="searchFn" clearable/>
            </div>
            <div class="tip">
                <Button type="primary" @click="searchFn" icon="ios-search">查询</Button>
            </div>
            <div class="btn">
                <Button icon="ios-download-outline" type="info" style="margin-right:10px;" @click="showDownload">批量导出</Button>
                <Button icon="ios-download-outline" type="info" @click="onDownLoad">导出</Button>
            </div>
        </div>
        <BatchDownload :showModal = "showModal"/>
    </div>
    
</template>
<script>
import { mapGetters } from 'vuex';
import BatchDownload from "./batchDownload"
export default {
    name:"search"
    ,data(){
        return{
            code: ''
            ,showModal:{
                show:false
            }
        }
    }
     ,computed:{
      ...mapGetters({
        sUser:'sUser'
      })
    }
    ,methods:{
        searchFn(){
            let t = this;
            if(t.code == ""){
                t.$Message.error({background: true,content: '请输入物料编码'});
                return;
            }
            t.$emit("getCode",t.code);
        }
        ,showDownload(){
            let t = this;
            t.showModal.show = true;
        }
        ,onDownLoad(){
            let t = this;
            if(!t.$parent.aTableData.length){
                t.$Message.error({background: true,content: '物料编码不能为空'});
                return;
            }
            let sUrl = 'material/exportBom.htm?materialCode='+ encodeURIComponent(t.code);
            if(t.sUser == 'admin'){
                sUrl += ('&u=' + t.sUser);
            }
            location.href = gMain.apiPath + t.$router.options.base + sUrl;
        }
    }
    ,components:{
        BatchDownload
    }
}
</script>
<style lang="less">
    .bom_tree_search{
        margin: 10px 50px;
        .tip{
            margin-left: 15px;
            display: inline-block;
        }
        .title{
            margin-right: 15px;
            // line-height: 32px;
        }
        .btn{
            float: right;
        }
    }
</style>